window.fbAsyncInit = function() {
  FB.init({
	appId : '548386225195405',
    status : true,
    cookie : true,
    xfbml : true
  });

  FB.getLoginStatus(function(response) {
   if(response.status === 'connected') {
     var uid = response.authResponse.userID;
	 FB.api('/me', function(response) {
      document.getElementById('facemenu').innerHTML = '<div id="facemenu-photo"><img src="http://graph.facebook.com/'+uid+'/picture?type=square" width="50" height="50" alt="Foto de Perfil" /></div><div id="facemenu-name">'+response.name+'</div><div id="facemenu-account">Mi Cuenta</div><div class="facemenu-option"><img src="'+url_template+'img/icon_view.png" alt="Visitado" style="vertical-align:top;" /> <a href="'+url_script+'visited.php" class="facemenu-link">Videos que haz Visitado</a></div><div class="facemenu-option"><img src="'+url_template+'img/icon_star.png" alt="Evaluado" style="vertical-align:bottom;" /> <a href="'+url_script+'rated.php" class="facemenu-link">Videos que haz Evaluado</a></div><div id="facemenu-logout"><img src="'+url_template+'img/icon_logout.png" alt="Cerrar Sesión" style="vertical-align:bottom;" /> <span onclick="face_logout();" style="cursor:pointer;">Salir</span></div>';
     });
   } else if (response.status === 'not_authorized') {
      document.getElementById('facemenu').innerHTML = '<div id="facemenu-text">Usa tu Facebook para Ingresar</div> <div id="facemenu-icon" onclick="face_login();"></div> <div id="facemenu-login" onclick="face_login();">Ingresar</div>';
   } else {
      document.getElementById('facemenu').innerHTML = '<div id="facemenu-text">Usa tu Facebook para Ingresar</div> <div id="facemenu-icon" onclick="face_login();"></div> <div id="facemenu-login" onclick="face_login();">Ingresar</div>';
   }
  });

};

(function(d, debug){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/es_LA/all" + (debug ? "/debug" : "") + ".js";
   ref.parentNode.insertBefore(js, ref);
 }(document, /*debug*/ false));
 
function face_login() {
 FB.login(function(response) {
   if(response.authResponse) {
      location.reload();
   }
 }, {scope: 'publish_actions,user_actions.video'});
}
function face_logout() {
 if(confirm("¿Seguro que deseas cerrar sesión?")) {
   FB.logout(function(response) {
     location.reload();
   });
 }
}